<template>
  <div class="app-main-container">
    <div class="app-main-title">
      {{ translate("lookHdOrder") }}
      <div class="goback" @click="goBack">
        <i class="el-icon-refresh-left" /> {{ translate("backPage") }}
      </div>
    </div>
    <QueryForm
      v-model="filters"
      :query-form-config="orderFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    >
      <template #btns>
        <!-- <el-button v-if="meta.indexOf('OrderListExport') > -1" :loading="exLoading" type="primary" @click="handleExport">{{translate('export')}}</el-button> -->
        <el-button :loading="exLoading" type="primary" @click="handleExport">{{
          translate("export")
        }}</el-button>
      </template>
    </QueryForm>
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        :label="translate('orderId')"
        prop="order"
        min-width="160"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <span class="primaryColor pointer" @click="detailClick(scope.row)">{{
            scope.row.orderId
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-for="item in activityPropList"
        :key="item.label"
        align="center"
        :label="item.label"
        :prop="item.prop"
        :min-width="item.minWidth"
        show-overflow-tooltip
      />
    </el-table>
    <Pagination
      :total="totalCount"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
    <Detail ref="DetailRef" />
  </div>
</template>

<script>
import { SecKillOrder, SecKillOrderEx, orderStatusConfig } from "@/api";
import Pagination from "@/components/paginations";
import Detail from "./detail.vue";
import { orderFormConfig, activityPropList } from "./config";
export default {
  name: "SecKillOrderList",
  components: {
    Pagination,
    Detail,
  },
  data() {
    return {
      secKillId: "",

      exLoading: false,
      orderFormConfig,
      activityPropList,
      totalCount: 0,
      list: [],
      meta: [],
      listLoading: false,
      orderType: [],
      pagination: {
        page: 1,
        rows: 10,
      },
      filters: {
        selTime: [],
      },
    };
  },
  created() {
    this.meta = this.$route.meta.buttons || [];
    if (this.$route.query.id) {
      this.secKillId = this.$route.query.id;
    }
    this.getOrderType();
    this.getList(1);
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout();
    });
  },
  methods: {
    getList(page) {
      this.listLoading = true;
      const { filters, pagination, secKillId } = this;
      if (page) {
        pagination.page = page;
        this.pagination.page = page;
      }
      if (filters.selTime.length > 0) {
        filters.startTime = filters.selTime[0];
        filters.endTime = filters.selTime[1];
      } else {
        filters.startTime = null;
        filters.endTime = null;
      }
      SecKillOrder({
        pagination,
        param: { ...filters, type: "0", secKillId },
      })
        .then((res) => {
          this.listLoading = false;
          if (res.errorCode === "000000") {
            this.list = res.recordList;
            this.totalCount = res.totalCount;
          }
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    goBack() {
      this.$router.replace("/application/SeckillActive");
    },
    handleSizeChange(value) {
      this.pagination.rows = value;
      this.getList(1);
    },
    handleExport() {
      this.exLoading = true;
      const { filters } = this;
      const param = { ...filters, type: "0", secKillId: this.secKillId };
      if (param.selTime.length > 0) {
        param.startTime = param.selTime[0];
        param.endTime = param.selTime[1];
      } else {
        param.startTime = null;
        param.endTime = null;
      }
      SecKillOrderEx({ param })
        .then((res) => {
          this.exLoading = false;
          if (res.errorCode === "000000") {
            window.open(res.record.showUrl, "_blank");
          }
        })
        .catch(() => {
          this.exLoading = false;
        });
    },
    detailClick(row) {
      console.log(row, "=====99");
      const { orderId } = row;
      this.$refs.DetailRef.getDetail(orderId);
      this.$refs.DetailRef.isShowModal = true;
    },
    getOrderType() {
      orderStatusConfig({ param: {} }).then((res) => {
        this.orderFormConfig.formItems[3].options = res.recordList;
      });
    },
    // 清空
    clear() {
      this.filters = {
        selTime: [],
      };
      this.getList(1);
    },
  },
};
</script>
